<template>
  <div >
    <el-tabs v-model="activityName" type="border-card" @tab-click="tabChange">
      <el-tab-pane v-if="tabHides.shopsManagement" name="/shopsManagement" class="shopsManagement" v-hasPermission="'management_branch:show'" label="门店管理">
        <div class="page-content">
          <router-view v-if="selectCategorys()"></router-view>
        </div>
      </el-tab-pane>
      <el-tab-pane v-if="tabHides.regionManagement" class="regionManagement" name="/regionManagement" label="区域管理">
        <div class="page-content">
          <router-view v-if="selectMaterials()"></router-view>
        </div>
      </el-tab-pane>

     <!-- <el-tab-pane v-if="tabHides.powerMould" name="/powerMould" v-hasPermission="'management_moban:show'" class="powerMould"  label="权限模板">
        <div class="page-content">
          <router-view v-if="selectUnits()"></router-view>
        </div>
      </el-tab-pane>-->
    </el-tabs>
  </div>
</template>
<script>
  //注意路径
  import AllRouter from '@/router/all.router'
  export default {
    data() {
      return {
        activityName: "/shopsManagement",
        tabHides:{
          regionManagement:true,
          shopsManagement:true,
          powerMould:true
        }
      };
    },
    watch: {
      $route(newValue, oldValue) {
        var path = this.$route.fullPath;

        console.log("-=========----:11");
        console.log(path);

        if (path == "/outfitManagement") {
          this.goHome();
          return;
        }
        if (path.startsWith("/regionManagement")) {
          this.activityName = "/regionManagement";
        } else if (path.startsWith("/shopsManagement")) {
          this.activityName = "/shopsManagement";
        }else if(path.startsWith("/powerMould")){
          this.activityName = "/powerMould";
        }
      },
    },
    created() {
      window.this = this;



      var permissions=JSON.parse(localStorage.getItem("permissions"));
      var admin=JSON.parse(localStorage.getItem("admin"));
      if((permissions['management_district:show']==undefined || !permissions) && !admin){
          this.tabHides.regionManagement=false;
      }
      if((permissions['management_branch:show']==undefined || !permissions) && !admin){
        this.tabHides.shopsManagement=false;
      }

      this.goHome();

    },
    methods: {

      goBack() {
        this.router.go(-1);
      },
      goHome() {
        if(!this.tabHides.regionManagement){
          this.activityName = "/regionManagement";
          this.router.push({ path: "/regionManagement/dataTable" });
        }else {

          this.activityName = "/shopsManagement";
          this.router.push({ path: "/shopsManagement/dataTable" });
        }

      },
      tabChange(active) {
        this.activityName = active.name;
        if (active.name == "/regionManagement") {
          this.router.push({ path: "/regionManagement/dataTable" });
        } else if (active.name == "/shopsManagement") {
          this.router.push({ path: "/shopsManagement/dataTable" });
        } else if(active.name == "/powerMould"){
          this.router.push({ path: "/powerMould/dataTable"});
        }else {
          this.router.push({ path: "/shopsManagement/dataTable" });
        }
      },
      selectMaterials(){
        return this.activityName.startsWith("/regionManagement");
      },
      selectCategorys(){
        return this.activityName.startsWith("/shopsManagement");
      },
      selectUnits(){
        return this.activityName.startsWith("/powerMould");
      }
    }
  };
</script>
<style scoped>
</style>
